#include "../00_Library_union/inc/my_list.h"
#include <iostream>
#include <vector>
#include <stack>
typedef unsigned int uint;
using namespace std;

void listHelper(slinkNodePtr head, vector<int>& ans) {
	if (head == nullptr) {
		return;
	}
	listHelper(head->next, ans);
	ans.push_back(head->data);
}
vector<int> reverseList(const slinkNodePtr head) {
	vector<int> ans;
	listHelper(head, ans);
	return ans;
}
vector<int> reverseList2(const slinkNodePtr head) {
	stack<slinkNodePtr> nodePtr;
	vector<int> ans;
	slinkNodePtr currPtr = head;
	while (currPtr) {
		nodePtr.push(currPtr);
		currPtr = currPtr->next;
	}
	while (!nodePtr.empty()) {
		ans.push_back(nodePtr.top()->data);
		nodePtr.pop();
	}
	return ans;
}
void test(char* name,vector<int>& buffer) {
	if (name != nullptr) 
		cout << name <<" begin:=============="<< endl;
	CLinkedList A;
	bool isRight = true;
	A.buffer2list(buffer);
	cout << "Solution 1:" << endl;
	vector<int> ans1 = reverseList(A.getHead());
	if (ans1.size() != buffer.size()) { isRight = false; }
	for (uint i = 0; i < ans1.size();i++) {
		if (ans1[i] != buffer[ans1.size() - 1 - i]) {
			isRight = true;
			break;
		}
	}
	if (isRight) {
		cout << "Passed" << endl;
	}
	else {
		cout << "Failed" << endl;
	}
	isRight = true;
	cout << "Solution 2:" << endl;
	ans1 = reverseList2(A.getHead());
	if (ans1.size() != buffer.size()) { isRight = false; }
	for (uint i = 0; i < ans1.size(); i++) {
		if (ans1[i] != buffer[ans1.size() - 1 - i]) {
			isRight = true;
			break;
		}
	}
	if (isRight) {
		cout << "Passed" << endl;
	}
	else {
		cout << "Failed" << endl;
	}
}
void test1() {
	vector<int> buffer = { 1,2,3,4,5,6 };
	test((char*)"test1",buffer);
}
void test2() {
	vector<int> buffer;
	test((char*)"test2", buffer);
}
void test3() {
	vector<int> buffer = {1000};
	test((char*)"test3", buffer);
}
int main() {
	test1();
	test2();
	test3();
}

